<template>
  <el-row>
    <div class="section-input">
      <el-radio-group v-model="question.answer" >
        <div v-if="question.style==='v'">
          <section v-for="option in question.options" :key="option.key">
            <el-radio :label="option.text" :checked="option.checked">{{option.text}}</el-radio>
          </section>
        </div>
        <div v-else>
          <section v-for="option in question.options" :key="option.key" style="float:left">
            <el-radio :label="option.text" :checked="option.checked">{{option.text}}
              <span v-if="tactics && option.tactics">——
                <span>{{makeTacticsName(tactics,option.tactics[option.tactics.length-1])}}：{{option.point}}</span>
              </span>
            </el-radio>
          </section>
        </div>
      </el-radio-group>
    </div>
  </el-row>
</template>

<script>
  import Vue from 'vue'//后续添加属性，需要vue联动
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  export default {
    name: "view-i-radio",
    props: ['question','tactics'],
    data() {
      return {
        sel:null
      }
    },
    watch:{
      question(nv,ov){
        // console.log(nv)
      }
    },
    created(){
      // let tmp = this.question.options.find(o=>{
      //   if(o.text === this.question.answer && o.tactics){
      //     console.log(o)
      //     return o
      //   }
      // })
      // if(tmp){
      //   Vue.set(this.question,'point',tmp.point)
      //   Vue.set(this.question,'tactics',tmp.tactics)
      // }
      // console.log(this.question)
    },
    methods: {
      makeTacticsName(a,id){
        let name = null
        for(let i=0;i<a.length;i++){
          let tmp = a[i]
          if(tmp.id === id){
            return tmp.name
          }else if(tmp.childrens){
            name = this.makeTacticsName(tmp.childrens,id)
            if(name != null) return name
          }
        }
        return name
      },
      // makeTacticsName(o){
      //   if(o.tactics.length === 1){//一级根目录
      //     let tmp = this.tactics.find(t=>t.id === o.tactics[0])
      //     return tmp.name
      //   }
      //   if(o.tactics.length>1){//多级策略
      //     let tmp = this.tactics.find(t=>t.id === o.tactics[0])
      //   }
      // }
    }
  }
</script>

<style scoped>

</style>
